package cn.shyouchi.wuguanjia.android.ui.statistic;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.api.attendance.AttendanceApi;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.subscribers.ProgressSubscriber;
import cn.shyouchi.wuguanjia.android.widget.TopBar;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import static cn.shyouchi.wuguanjia.android.R.id.topBar;

public class SignStatisticManagerActivity extends BaseActivity {


    @BindView(topBar)
    TopBar mTopBar;
    @BindView(R.id.rv_events)
    RecyclerView mRvEvents;

    SignStatisticManagerAdapter mAdapter;

    List<SignStatisticManagerEntity.ResultMessageBean> mEntities = new ArrayList<>();

    AttendanceApi mAttendanceApi;

    @Override
    public int initContentView() {
        return R.layout.activity_sign_statistic_manager;
    }

    @Override
    public void initInjector() {
        mAttendanceApi = new AttendanceApi(mContext);

    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());


//        mEntities.add(new SignStatisticManagerEntity());
//        mEntities.add(new SignStatisticManagerEntity());
//        mEntities.add(new SignStatisticManagerEntity());
//        mEntities.add(new SignStatisticManagerEntity());
//        mEntities.add(new SignStatisticManagerEntity());
//        mEntities.add(new SignStatisticManagerEntity());



        mRvEvents.setLayoutManager(new GridLayoutManager(mContext, 2));
        mAdapter = new SignStatisticManagerAdapter(mEntities);

        mRvEvents.setAdapter(mAdapter);


        mAttendanceApi.getEvents()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ProgressSubscriber<SignStatisticManagerEntity>(mContext) {
                    @Override
                    public void onNext(SignStatisticManagerEntity entity) {
                        mEntities.clear();
                        mEntities.addAll(entity.getResultMessage());
                        mAdapter.notifyDataSetChanged();
                    }
                });

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }

}
